<? 
	require_once('lib/nusoap.php'); 
	include("connect/connect.php");

	$ws_client = new soapclient('http://127.0.0.1/dsccmis/datasource_webservice/get_visadmission_last.php?wsdl',true); 
	$result = $ws_client->call('getAdmission_last'); 


	if($result<>""){
		$last_rev_status="สำเร็จ";
	}else{
		$last_rev_status="ล้มเหลว";
	}


	$arr_rec = explode(";",$result); 

	//last_rev_record
	$last_rev_record=count($arr_rec)-1;
	
	//charset
	mysql_select_db("dscc",$c);
	mysql_query("set names utf8");
	
	//
	$tempY=date("Y");
	if($tempY<"2550"){
		$tempY=(int)$tempY+543;
	}
	$datetime_receive= $tempY.date("-m-d-H:i");

	//insert rev_militaryvictim
	foreach($arr_rec as $rec){
		$fld=explode(",",$rec);
		if($fld[0]<>""){
			$sql = "insert into rev_visadmission_last(aid, hosp, hn, id,prename,name,fname, residence,adate,atime,vaplace, hdate, htime, rdate, rtime, icdcause, vstaward, frelate1, fprename1, fname1, ffname1, fid1, frelate2, fprename2, fname2, ffname2, fid2, frelate3, fprename3, fname3, ffname3, fid3, frelate4, fprename4, fname4, ffname4, fid4, frelate5, fprename5, fname5, ffname5, fid5, frelate6, fprename6, fname6, ffname6, fid6, frelate7, fprename7, fname7, ffname7, fid7, frelate8, fprename8, fname8, ffname8, fid8, frelate9, fprename9, fname9, ffname9, fid9, frelate10, fprename10, fname10, ffname10, fid10, frelate11, fprename11, fname11, ffname11, fid11, frelate12, fprename12, fname12, ffname12, fid12, frelate13, fprename13, fname13, ffname13, fid13, frelate14, fprename14, fname14, ffname14, fid14, frelate15, fprename15, fname15, ffname15, fid15,datetime_receive) values('$fld[0]','$fld[1]','$fld[2]','$fld[3]','$fld[4]','$fld[5]','$fld[6]','$fld[7]','$fld[8]','$fld[9]','$fld[10]','$fld[11]','$fld[12]','$fld[13]','$fld[14]','$fld[15]','$fld[16]','$fld[17]','$fld[18]','$fld[19]','$fld[20]','$fld[21]','$fld[22]','$fld[23]','$fld[24]','$fld[25]','$fld[26]','$fld[27]','$fld[28]','$fld[29]','$fld[30]','$fld[31]','$fld[32]','$fld[33]','$fld[34]','$fld[35]','$fld[36]','$fld[37]','$fld[38]','$fld[39]','$fld[40]','$fld[41]','$fld[42]','$fld[43]','$fld[44]','$fld[45]','$fld[46]','$fld[47]','$fld[48]','$fld[49]','$fld[50]','$fld[51]','$fld[52]','$fld[53]','$fld[54]','$fld[55]','$fld[56]','$fld[57]','$fld[58]','$fld[59]','$fld[60]','$fld[61]','$fld[62]','$fld[63]','$fld[64]','$fld[65]','$fld[66]','$fld[67]','$fld[68]','$fld[69]','$fld[70]','$fld[71]','$fld[72]','$fld[73]','$fld[74]','$fld[75]','$fld[76]','$fld[77]','$fld[78]','$fld[79]','$fld[80]','$fld[81]','$fld[82]','$fld[83]','$fld[84]','$fld[85]','$fld[86]','$fld[87]','$fld[88]','$fld[89]','$fld[90]','$fld[91]','$datetime_receive')";
			//echo "<br>".$sql;
			$rs=mysql_query($sql);
		}
	}

	//$total_record
	$sql = "select count(*) as c from rev_visadmission_last";
	$rs=mysql_query($sql);
	$rows=mysql_fetch_array($rs);
	$total_record=$rows["c"];

	//
	$sql = "update rev_status set total_record=$total_record,last_rev_record=$last_rev_record,last_rev_datetime='$datetime_receive',last_rev_status='$last_rev_status' where dsid='V1' and datasettype='VIS';";
	//echo "<br>".$sql;
	$rs=mysql_query($sql);
	if(($last_rev_status=="สำเร็จ") && ($rs)){
		echo "<br>ดึงข้อมูลจาก VIS !!! สำเร็จ !!!";
	}else{
		echo "<br>ดึงข้อมูลจาก VIS !!! ล้มเหลว !!!";
	}
	//
	mysql_close();
?> 
